/*
 * Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
 */

package com.xci.edu.module.background.controller;

import com.github.lvyanyang.annotation.Authorize;
import com.github.lvyanyang.core.BaseWebController;
import com.github.lvyanyang.core.BoolResult;
import com.github.lvyanyang.core.Const;
import com.github.lvyanyang.core.XCI;
import com.xci.edu.core.entity.ExamRecordDetails;
import com.xci.edu.core.filter.ExamRecordDetailsFilter;
import com.xci.edu.core.service.ExamRecordDetailsService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 考试试题明细页面控制器
 * @author 马星俊 maxingjun@xci96716.com
 * @since 2020-11-25 10:55:25
 */
@Authorize
@Controller
@RequestMapping(value = "/background/examRecordDetails")
public class ExamRecordDetailsController extends BaseWebController {
    /** 考试试题明细服务 */
    @Resource private ExamRecordDetailsService examRecordDetailsService;

    //region 页面

    /** 首页 */
    @GetMapping
    @Authorize(code = "background.examRecordDetails")
    public String index() {
        return "background/examRecordDetails/index";
    }

    /** 新建页 */
    @GetMapping("/create")
    @Authorize(code = "background.examRecordDetails.insert")
    public String create(ModelMap map) {
        createMark(map);
        var entity = new ExamRecordDetails();
//        entity.setId(XCI.nextId());
        // entity.setRecordId();
        // entity.setQuestionId();
        // entity.setAnswer();
        // entity.setStatus();
        // entity.setPath();
        map.put("entity", entity);
        return "background/examRecordDetails/edit";
    }

    /** 编辑页 */
    @GetMapping("/edit")
    @Authorize(code = "background.examRecordDetails.update")
    public String edit(String id, ModelMap map) {
        var entity = examRecordDetailsService.selectById(Long.valueOf(id));
        XCI.checkNotFoundData(entity, id);
        map.put("entity", entity);
        return "background/examRecordDetails/edit";
    }

    /** 详情页 */
    @GetMapping("/details")
    public String details(String id, ModelMap map) {
        var entity = examRecordDetailsService.selectById(Long.valueOf(id));
        XCI.checkNotFoundData(entity, id);
        map.put("entity", entity);
        return "background/examRecordDetails/details";
    }

    //endregion

    //region 处理

    /** 表格查询 */
    @ResponseBody
    @PostMapping("/grid")
    @Authorize(code = "background.examRecordDetails.select")
    public BoolResult grid(ExamRecordDetailsFilter filter) {
        return BoolResult.success(examRecordDetailsService.selectPageList(filter));
    }

    /** 新建保存 */
    @ResponseBody
    @PostMapping("/createSave")
    @Authorize(code = "background.examRecordDetails.insert")
    public BoolResult createSave(@ModelAttribute ExamRecordDetails entity) {
        return examRecordDetailsService.insert(entity);
    }

    /** 修改保存 */
    @ResponseBody
    @PostMapping("/updateSave")
    @Authorize(code = "background.examRecordDetails.update")
    public BoolResult updateSave(@ModelAttribute ExamRecordDetails entity) {
        return examRecordDetailsService.update(entity);
    }

    /** 删除 */
//    @ResponseBody
//    @PostMapping("/delete")
//    @Authorize(code = "background.examRecordDetails.delete")
//    public BoolResult delete(String ids) {
//        return examRecordDetailsService.delete(ids);
//    }

    /** 修改状态 */
    @ResponseBody
    @PostMapping("/status")
    @Authorize(code = "background.examRecordDetails.updateStatus")
    public BoolResult status(String id, Integer status) {
        examRecordDetailsService.updateStatus(id, XCI.toBool(status));
        return BoolResult.success();
    }

    /** 导出 */
    @GetMapping("/export")
    @Authorize(code = "background.examRecordDetails.export")
    public void export(ExamRecordDetailsFilter filter) {
        XCI.exportExcel(examRecordDetailsService.selectList(filter), ExamRecordDetails.class, "考试试题明细列表");
    }


    //endregion
}